package com.qiaolang.controller;

import com.qiaolang.Service.CardServiceImpl;
import com.qiaolang.Service.UserServiceImpl;
import com.qiaolang.pojo.Card;
import com.qiaolang.pojo.ID;
import com.qiaolang.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by lenovo on 2017/11/12.
 */
@RestController
@CrossOrigin
@RequestMapping("/card")
public class CardController {
    @Autowired
    private CardServiceImpl service;

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public ResponseEntity<Void> login(@RequestBody Card card){
        if(service.register(card)!=false){//如果登录成功
            return new ResponseEntity<Void>(HttpStatus.OK);
        }else{
            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
        }
    }
    @RequestMapping(value = "/querybyid/{userno}",method = RequestMethod.POST)
    public ResponseEntity<Card> query(@PathVariable String userno){
        Card card=service.queryById(userno);
        if(card!=null){//如果删除成功
            return new ResponseEntity<Card>(card,HttpStatus.OK);
        }else{
            return new ResponseEntity<Card>(card,HttpStatus.CONFLICT);
        }
    }





    //删除和修改的是users表里面的数据
    @RequestMapping(value = "/del/{userno}",method = RequestMethod.DELETE)
    public ResponseEntity<Void> del(@PathVariable String userno){
        if(service.del(userno)){//如果删除成功
            return new ResponseEntity<Void>(HttpStatus.OK);
        }else{
            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
        }
    }
    @RequestMapping(value = "/upt/{userno}/{role}",method = RequestMethod.POST)
    public ResponseEntity<Void> upt(@PathVariable String userno,@PathVariable String role){
        if(service.upt(userno,role)){//如果修改成功
            return new ResponseEntity<Void>(HttpStatus.OK);
        }else{
            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
        }
    }

    @RequestMapping(value = "/uptStatus/{userno}",method = RequestMethod.POST)
    public ResponseEntity<Void> uptStatus(@PathVariable String userno){
        if(service.uptStatus(userno)){//如果修改成功
            return new ResponseEntity<Void>(HttpStatus.OK);
        }else{
            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
        }
    }

    @RequestMapping(value = "/buka/{userno}",method = RequestMethod.POST)
    public ResponseEntity<Void> buKa(@PathVariable String userno){
        if(service.buKa(userno)){//如果修改成功
            return new ResponseEntity<Void>(HttpStatus.OK);
        }else{
            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
        }
    }


    @RequestMapping(value = "/getBalance/{userno}",method = RequestMethod.POST)
    public ResponseEntity<String> getBalance(@PathVariable String userno){
        String balance=service.getBalance(userno);
        if(balance!=null){//如果修改成功
            return new ResponseEntity<String>(balance,HttpStatus.OK);
        }else{
            return new ResponseEntity<String>(balance,HttpStatus.CONFLICT);
        }
    }

    @RequestMapping(value = "/chongZhi/{userno}/{balance}",method = RequestMethod.POST)
    public ResponseEntity<Void> chongZhi(@PathVariable String userno,@PathVariable int balance){

        if(service.chongZhi(userno,balance)){//如果修改成功
            return new ResponseEntity<Void>(HttpStatus.OK);
        }else{
            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
        }
    }
}
